<?php
loadTemp("admin/models/member/member_header.php");
?>
<script type="text/javascript">
$(document).ready(function(){
	loadAdminTopItem();
	activeAdminTopItem("s_c_edit_user");
});
</script>
<?php checkAdminPermission("admin.member.edit_user","admin.class.*");?>
<!-- Start -->
<script type="text/javascript">
$(document).ready(function(){
	$("#form_edit_user_login_data").hide();
	$("#form_edit_user_profile").hide();
	bindAjaxForm($("#form_edit_user_login_data"),s_edituser_onSuccess,s_edituser_onError,"admin_di");
	bindAjaxForm($("#form_edit_search"),s_edituser_onSuccess,s_edituser_onError,"admin_di");
	bindAjaxForm($("#form_edit_user_profile"),s_edituser_onSuccess,s_edituser_onError,"admin_di");
	
	$(".s_master_selecter").hide();
});
function s_edituser_onSuccess(data){
	console.log(data);
	s_edituser_operatedone(data.code,data.message,data.data);
}
function s_edituser_onError(data){
	console.log(data);
	s_edituser_operatedone(-101,"服务器返回了未知的数据，请上报管理员",data.responseText);
}
function s_edituser_operatedone(id,message,data){
	if(id==-101){
		showMessage("s_edituser_message",-101,message+"<br><br><pre>"+data+"</pre>");
		return;
	}
	if(id!=0&&id!=3){
		showMessage("s_edituser_message",id,message);
	}
	if(id==0){
		showMessage("s_edituser_message",id,message);
	}
	if(data.op=="user_search"){
		$("#form_edit_user_login_data").show();
		$("#form_edit_user_profile").show();
		$("#form_edit_search").hide();
		a_m_e_u_loadProfile(data);
		a_m_e_u_loadLoginData(data);
		$(".s_uid").attr("value",data.uid);
	}
	if(data.op=="edit_done_login"){
		$("#form_edit_user_login_data").hide();
	}
	if(data.op=="edit_done_profile"){
		$("#form_edit_user_profile").hide();
	}
}
function a_m_e_u_loadLoginData(data){
	  $("#s_mail").attr("value", data.logindata.mail);
	  $("#s_phonenumber").attr("value", data.logindata.phone);
}
function a_m_e_u_loadProfile(data){
    if (data.isNew) {
        $("#s_p_new").removeClass("hidden");
        return;
    }
    setRadiobox(data.profile.gender, "c_");
    var gender = data.profile.gender;
    $("#s_birthday").attr("value", data.profile.birthday);
    var user_type = data.profile.user_type;
    if (user_type == 0) $("#u_student").click();
    if (user_type == 1) $("#u_parent").click();
    if (user_type == 2) $("#u_teacher").click();
    $("#s_name").attr("value", data.profile.name);
    $("#s_introduce").html(data.profile.introduce);
    $("#s_motto").html(data.profile.motto);  
}
</script>
<div class="s_admin_in_container">
	<h2 class="ui dividing header">编辑成员</h2>
	<div class="ui message">
		<div class="header">小提示</div>
		<ul class="list">
			<li>你可以在这里编辑成员的存档和登录信息</li>
			<li>请先在搜索框内输入目标的登录信息（UID/手机/Mail</li>
			<li>确定后再进行编辑</li>
		</ul>
	</div>
	<div class="ui message hidden" id="s_edituser_message"></div>
	<form class="ui form admin_form" url="admin.php?mod=member&ajax=true&op=search_edit_user" id="form_edit_search">
		<div class="ui action fluid input">
			<div class="ui left icon input">
				<input type="text" name="account" placeholder="目标账号" id="s_edit_search">
				<i class="users icon"></i>
			</div>
			<button class="ui button submit" type="submit">确定</button>
		</div>
	</form>
	<form class="ui form admin_form" url="admin.php?mod=member&ajax=true&op=edit_user_login_data" id="form_edit_user_login_data">
		<h4 class="ui dividing header">用户登录信息编辑</h4>
		<input type="hidden" class="s_uid" name="uid">
		<div class="field">
			<label>邮箱</label>
			<div class="field">
				<input id="s_mail" type="text" name="mail" placeholder="邮箱">
			</div>
			<label>手机号</label>
			<div class="field">
				<input id="s_phonenumber" type="text" name="phonenumber" placeholder="手机号">
			</div>
			<label>密码（如无需更改请保持这样）</label>
			<div class="field">
				<input id="password" type="password" name="passwd" placeholder="密码" value="keep01">
			</div>
		</div>
		<button type="submit" class="ui submit button">提交</button>
	</form>
	<form class="ui form admin_form" url="admin.php?mod=member&ajax=true&op=edit_user_profile" id="form_edit_user_profile">
		<h4 class="ui dividing header">用户资料编辑</h4>
		<input type="hidden" class="s_uid" name="uid">
		<div class="field">
			<label>姓名：</label>
			<input type="text" name="name" placeholder="name" id="s_name">
		</div>
		<div class="inline fields">
			<div class="field">
				<label>性别：</label>
				<div class="ui radio checkbox" id="c_false">
					<input type="radio" name="gender" value="0" class="hidden">
					<label>男</label>
				</div>
			</div>
			<div class="field">
				<div class="ui radio checkbox" id="c_true">
					<input type="radio" name="gender" value="1" class="hidden">
					<label>女</label>
				</div>
			</div>
		</div>
		<div class="inline fields">
			<div class="field">
				<label>账户类型：</label>
				<div class="ui radio checkbox" id="u_student">
					<input type="radio" name="user_type" value="0" class="hidden">
					<label>学生</label>
				</div>
			</div>
			<div class="field">
				<div class="ui radio checkbox" id="u_parent">
					<input type="radio" name="user_type" value="1" class="hidden">
					<label>家长</label>
				</div>
			</div>
			<div class="field">
				<div class="ui radio checkbox" id="u_teacher">
					<input type="radio" name="user_type" value="2" class="hidden">
					<label>教职工</label>
				</div>
			</div>
		</div>
		<div class="field">
			<label>生日：</label>
			<input type="date" name="birthday" placeholder="yourbirthday" id="s_birthday">
		</div>
		<div class="field">
			<label>自我介绍</label>
			<textarea name="introduce" form="form_edit_user_profile" rows="3" id="s_introduce"></textarea>
		</div>
		<div class="field">
			<label>座右铭</label>
			<textarea name="motto" form="form_edit_user_profile" rows="1" id="s_motto"></textarea>
		</div>
		<button type="submit" class="ui submit button">提交</button>
	</form>
</div>